Is each of the following a different character?

0       O         o

Answer:

Yes. Each of the above (zero, Capital 'O', and lower case 'o') is a different character and has its own 16 bit code.

Character Literals

In a program, a character literal is surrounded with an apostrophe on both sides:

'm'          'y'               'A'

In a program, control characters are represented with several characters inside the apostrophes:

'\n'          '\t'

Each of these is what you do in a program to get a single char. The first one represents the 16 bit newline character and the second one represents the tabulation character. You will rarely use any control characters other than these two. Several others are listed in the Java documentation.

Warning: The following is not a character literal:

"Hello"

This is, in fact, a String, which is not primitive data. Strings are surrounded by double quotes ", not by apostrophes.

QUESTION 14:

What is wrong with the following char literal:

"W"